# Dockerfile for CUC Online Judge - Judge
FROM ubuntu:18.04
# 曾经的维护者
# PROJECT Dockerfile for Verwandlung Online Judge - Judge
# MAINTAINER Haozhe Xie "cshzxie@gmail.com"
MAINTAINER Jinhe Zhang "307100890@qq.com"

########### User Settings ###########
# 如果你在生产环境运行，请检查这里的设置和后文暴露的端口
# User Settings
ARG MYSQL_USER_PASS=U3bEwhRHnD6xNVpb
ARG MYSQL_HOST=voj.web
ARG MYSQL_PORT=3306
ARG ACTIVEMQ_HOST=voj.web
ARG ACTIVEMQ_PORT=61616
########### User Settings ###########

# Set environment variables.
ENV HOME          /root
ENV JAVA_HOME     /usr/lib/jvm/java-11-openjdk-amd64
ENV M2_HOME       /opt/maven

# Define working directory.
WORKDIR           /root

########### Init for Debug ###########
# 如果你在生产环境运行，请注释这段代码除了`RUN apt update`的其他部分
# init
RUN apt update
## set passwd
RUN echo "root:voj" | chpasswd
## vim sshd
RUN apt install -y vim openssh-server
RUN mkdir /run/sshd && /usr/sbin/sshd
########### Init for Debug ###########

## Set TimeZone
RUN apt install -y tzdata
RUN echo -e "\nTZ='Asia/Shanghai'; export TZ\n" >> ~/.profile
RUN bash -c "source ~/.profile"

# Install Java
RUN apt-get install -y openjdk-11-jdk

# Install Maven
RUN apt-get install -y wget
RUN wget https://archive.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
RUN tar -xf apache-maven-3.5.4-bin.tar.gz -C /opt
RUN mv /opt/apache-maven-3.5.4 /opt/maven
RUN rm apache-maven-3.5.4-bin.tar.gz

# Setup Judger Project
RUN apt-get install -y git gcc g++ make
RUN git clone https://gitee.com/xuanyusan/cuc-online-judge-public.git
RUN sed -i "s@jdbc.url = jdbc:mysql://localhost:3306@jdbc.url = jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}@g" cuc-online-judge-public/judger/src/main/resources/voj.properties
RUN sed -i "s/jdbc.username = root/jdbc.username = voj/g" cuc-online-judge-public/judger/src/main/resources/voj.properties
RUN sed -i "s/jdbc.password = /jdbc.password = ${MYSQL_USER_PASS}/g" cuc-online-judge-public/judger/src/main/resources/voj.properties
RUN sed -i "s/localhost:61616/${ACTIVEMQ_HOST}:${ACTIVEMQ_PORT}/g" cuc-online-judge-public/judger/src/main/resources/voj.properties
RUN mkdir -p cuc-online-judge-public/target/classes
RUN $M2_HOME/bin/mvn package -DskipTests -f cuc-online-judge-public/judger/pom.xml

# Setup Compliers
RUN apt-get install -y python3
RUN ln -s /usr/bin/python3 /usr/bin/python

# Run Judger
CMD ["java", "-jar", "cuc-online-judge-public/judger/target/voj.judger.jar"]
